<html>
<head>
    <!-- 其他头部内容 -->
    <script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
<!--    <script src="https://cdn.jsdelivr.net/sockjs/1.5.2/sockjs.min.js"></script>-->
<!--    <script src="https://cdn.jsdelivr.net/stomp.js/2.3.3/stomp.min.js"></script>-->
    <script type="application/javascript" src="https://cdn.bootcss.com/sockjs-client/1.5.2/sockjs.min.js"></script>
    <script type="application/javascript" src="https://cdn.bootcss.com/stomp.js/2.3.3/stomp.min.js"></script>
</head>
<body>
<!-- 其他页面内容 -->
<!--<script type="application/javascript" src="https://cdn.bootcss.com/sockjs-client/1.5.2/sockjs.min.js"></script>-->
<!--<script type="application/javascript" src="https://cdn.bootcss.com/stomp.js/2.3.3/stomp.min.js"></script>-->
<script>

    // var socket = new SockJS("/websocket-endpoint");
    var socket = new SockJS('http://localhost:8080/websocket-endpoint');
    var stompClient = Stomp.over(socket);

    stompClient.connect({}, function () {
        // console.log('Connected: ' + frame);

        stompClient.subscribe('/topic/greetings', function (greeting) {
            console.log('Received:', greeting.body);
            // console.log('Received: ' + JSON.parse(greeting.body).content);
        });
        sendMessage();
    });
    function sendMessage() {
        stompClient.send("/app/hello", {}, JSON.stringify({'message': 'World'}));
    }
    // stompClient.connect({}, function (){
    //     // console.log('Connected: ' + frame);
    //     sendMessage();
    // });



</script>

</body>
</html>

